package net.cloudcodex.client.home.view.panel.campaign;

import java.util.Date;
import java.util.List;

import net.cloudcodex.client.home.view.HomeView.Message;
import net.cloudcodex.client.home.view.panel.NotificationIcone;
import net.cloudcodex.client.home.view.panel.StoryResponsPanel;
import net.cloudcodex.client.widgets.CampaignAvatar;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;

public class HomeCampaignPanel extends DockPanel {

	private CampaignAvatar campaignAvatar = new CampaignAvatar();
	private HomeCampaignInfoPanel campaignInfoPanel = new HomeCampaignInfoPanel();
	private NotificationIcone notifIcone = new NotificationIcone();
	private StoryResponsPanel campaignStoryResponsPanel = new StoryResponsPanel();
	private Message message;
	private long campaignId;

	public HomeCampaignPanel() {
		this.add(campaignAvatar, DockPanel.WEST);
		HorizontalPanel centerPanel = new HorizontalPanel();
		centerPanel.add(campaignInfoPanel);
		centerPanel.add(campaignStoryResponsPanel);
		this.add(centerPanel, DockPanel.CENTER);
		this.setStyleName("characterPanel");
	}

	public void initComponent() {
		campaignStoryResponsPanel.setMessage(message);
		campaignInfoPanel.setMessage(message);
		campaignInfoPanel.initPanel();
		campaignStoryResponsPanel.initPanel();
		campaignStoryResponsPanel.setStyleName("campaignStoryResponsPanel");
		refreshNotifsIcone();
	}

	public void refreshNotifsIcone() {
		if (notifIcone.hasNotifs()) {
			this.add(notifIcone, DockPanel.EAST);
		} else {
			this.remove(notifIcone);
		}

	}

	public void setMessage(Message message) {
		this.message = message;

	}

	public void addCampaign(long id, String icon, String name) {
		this.campaignId = id ;
		campaignAvatar.initComponent(icon, name, true);
		campaignAvatar.setId(id);
	}

	public void addCampaignInfos(Date creationDate,
			List<String> activeCharacters) {
		campaignInfoPanel.setCampaignPlayers(activeCharacters);
		campaignInfoPanel.setDateStartedCampaign(creationDate);
	}

	public void addNotification(String message, Date date) {
		notifIcone.addNotification(message, date);
	}

	public void addStoryBoardResponse(List<String> charactersResponder) {
		campaignStoryResponsPanel.addStoryBoardResponse(charactersResponder);
	}

	public HasClickHandlers getCampaignAvatar() {
		return campaignAvatar;
	}

	public Long getCampaignId() {
		// TODO Auto-generated method stub
		return campaignId;
	}

	public HasClickHandlers getSeeMoreAnchor() {
		// TODO Auto-generated method stub
		return campaignStoryResponsPanel;
	}

}
